package com.muzi.onvif.PTZ.requset;

import com.muzi.onvif.beans.OnvifDevice;
import com.muzi.onvif.util.PasswordUtils;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.codec.binary.Base64;

import java.text.MessageFormat;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class StopRequest {
    private String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
            "<s:Envelope xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:tptz=\"http://www.onvif.org/ver20/ptz/wsdl\" xmlns:tt=\"http://www.onvif.org/ver10/schema\">\n" +
            "  <s:Header>\n" +
            "    <wsse:Security xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\" xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">\n" +
            "      <wsse:UsernameToken>\n" +
            "        <wsse:Username>{0}</wsse:Username>\n" +
            "        <wsse:Password Type=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest\">{1}</wsse:Password>\n" +
            "        <wsse:Nonce>{2}</wsse:Nonce>\n" +
            "        <wsu:Created>{3}</wsu:Created>\n" +
            "      </wsse:UsernameToken>\n" +
            "    </wsse:Security>\n" +
            "  </s:Header>\n" +
            "  <s:Body>\n" +
            "    <tptz:Stop>\n" +
            "      <tptz:ProfileToken>{4}</tptz:ProfileToken>\n" +
            "      <tptz:PanTilt>true</tptz:PanTilt>\n" +
            "      <tptz:Zoom>true</tptz:Zoom>\n" +
            "    </tptz:Stop>\n" +
            "  </s:Body>\n" +
            "</s:Envelope>";

    public String getXml(OnvifDevice device,String profileToken) {
        return MessageFormat.format(xml,device.getUsername(), PasswordUtils.encryptPassword(device.getPassword()), Base64.encodeBase64String(PasswordUtils.nonce.getBytes()),PasswordUtils.utcTime,profileToken);

    }
}
